package com.itranswarp.learnjava;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.time.Period;

/**
 * Learn Java from https://www.liaoxuefeng.com/
 * 
 * @author liaoxuefeng
 */
public class Main {


	public static void main(String[] args)throws Exception {
		Person person = new Person("冰晶");

		Class cls = Person.class;

		Method m = cls.getDeclaredMethod("changeNameToJack");
		m.setAccessible(true);
		Object invoke = m.invoke(person);
		System.out.println(invoke.toString());


	}
}

class Person{
	private String name;

	public Person(String name) {
		this.name = name;
	}

	public void changeName(String name){
		this.name = name;
	}

	private Person changeNameToJack(){
		this.name = "Jack";
		return new Person(name);
	}

	@Override
	public String toString() {
		return "Person{" +
				"name='" + name + '\'' +
				'}';
	}
}


class User{
	private String name;
	private int age;

	public void changeName(String name){
		this.name = name;
	}

	@Override
	public String toString() {
		return "User{" +
				"name='" + name + '\'' +
				", age=" + age +
				'}';
	}

	public User(){}
	public User(String name , int age){
		this.name = name;
		this.age = age;

	}

	public String getName(){
		return name;
	}

	public void setName(String name){
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
}